<%--
  Created by IntelliJ IDEA.
  User: EDY
  Date: 2023-11-01
  Time: 8:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.js"></script>
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.bundle.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../../js/jquery.form.js"></script>
    <script src="../../js/jquery.validate.js"></script>
    <script src="../../js/messages_zh.js"></script>
    <script src="js/change.js"></script>
    <script src="js/update.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css"></link>
    <link rel="stylesheet" href="../../css/bootstrap.min.css"></link>
    <style>
        #form {
            position: absolute;
            top: 10%;
            bottom: 10%;
            left: 10%;
            right: 10%;
            margin: auto;
        }
    </style>
</head>
<body onload="infoShow()">
    <table width="100%">
        <tbody>
        <tr height="20">
            <td>
                <span style="color: #0c84ff">您正在做的业务是：生产管理--产品生产工序设计--产品生产工序设计单变更</span>
            </td>
        </tr>
        <tr height="20">
            <td align="right">
                <input id="add" type="button" value="添加工序">
                <input id="del" type="button" value="删除新工序">
                <input type="button" onclick="checkOk()" value="提交">
                <input type="button" value="返回" onclick="history.back();">
            </td>
        </tr>
        </tbody>
    </table>
    <div>
        <table width="80%" align="center" border="0" bgcolor="#FFFFFF">
            <tbody>
            <tr>
                <td rowspan="2">
                    <table cellspacing="0" cellpadding="0" width="100%" style="border: #333333 1px solid;">
                        <tbody>
                        <tr>
                            <td colspan="4" height="10">
                                <table width="100%">
                                    <tbody>
                                    <tr>
                                        <td>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5"><font size="4"><b>物料组成设计单</b></font>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5">&nbsp;</td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center" id="theObjTable">
                                                <tbody>
                                                <tr height="20px">
                                                    <td align="right" width="12%">
                                                        设计单编号：
                                                    </td>
                                                    <td>
                                                        <input type="text" readonly name="designId" style="outline: none;border: 0px">
                                                    </td>
                                                    <td>
                                                        设计人：
                                                    </td>
                                                    <td>
                                                        <input type="text" name="designer" style="outline: none;width: 100%;border:0px;border-bottom:1px solid;">
                                                    </td>
                                                </tr>
                                                <tr height="20px">
                                                    <td align="right">
                                                        产品名称：
                                                    </td>
                                                    <td>
                                                        <input type="text" readonly name="productName" style="outline: none;border: 0px">
                                                    </td>
                                                    <td align="left" >
                                                        产品编号：
                                                    </td>
                                                    <td>
                                                        <input type="text" readonly name="productId" style="outline: none;border: 0px">
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5">&nbsp;</td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table border="1" cellspacing="0" cellpadding="0"
                                                   align="center" id="tableOnlineEdit" style="text-align: center;">
                                                <thead>
                                                <tr height="20" bgcolor="#D2E9FF">
                                                    <td bordercolor="#DEDBD6" align="left" width="5%">
                                                        序号
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="13%">工序名称
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="11%">工序编号
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left" width="8%">
                                                        描述
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left" width="8%">
                                                        工时数
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left" width="8%">
                                                        工时单位
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="11%">单位工时成本（元）
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="13%">工时成本小计（元）
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="13%">删除
                                                    </td>
                                                </tr>
                                                </thead>
                                            </table>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5">&nbsp;</td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center" id="theTable">
                                                <tbody>
                                                <tr height="20px">
                                                    <td align="right" width="10%">工时总成本：
                                                    </td>
                                                    <td width="30%">
                                                        <input name="costPriceSum" readonly style="border: 0px;outline: none">
                                                    </td>
                                                </tr>
                                                <tr height="20px">
                                                    <td align="right" width="10%">变更人：
                                                    </td>
                                                    <td width="30%">
                                                        <input type="text" name="changer" value="${sysUsers.loginId}" readonly style="outline: none;width: 100%;border:0px;border-bottom:1px solid;">
                                                    </td>
                                                    <td align="left" width="10%">变更时间：
                                                    </td>
                                                    <td align="left" width="30%">
                                                        <input name="changeTime" readonly style="border: 0px;outline: none">
                                                    </td>
                                                </tr>
                                                <tr height="20">
                                                    <td align="right" width="9%">设计要求：
                                                    </td>
                                                    <td align="left" colspan="3" width="89%">
                                                        <textarea rows="4" name="procedureDescribe" style="width: 100%"></textarea>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap="" width="56">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap="" height="100"></td>
                            <td></td>
                        </tr>

                        <tr valign="bottom">
                            <td colspan="4" nowrap="" align="center"></td>
                        </tr>

                        <tr>
                            <td colspan="4" nowrap="" align="right"></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
                <td width="1" bgcolor="#ffffff" height="2"></td>
                <td width="1" bgcolor="#ffffff" height="2"></td>
                <td width="1" bgcolor="#ffffff" height="2"></td>
            </tr>
            <tr>
                <td width="1" bgcolor="#333333" height="120"></td>
                <td width="1" bgcolor="#666666" height="120"></td>
                <td width="1" bgcolor="#999999" height="120"></td>
            </tr>
            <tr valign="top" align="right">
                <td colspan="4">
                    <table cellspacing="0" cellpadding="0" align="center" border="0">
                        <tbody>
                        <tr>
                            <td bgcolor="#333333" height="1"></td>
                        </tr>
                        <tr>
                            <td bgcolor="#666666" height="1"></td>
                        </tr>
                        <tr>
                            <td bgcolor="#999999" height="1"></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <form class="modal fade" id="modalform" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content" style="width: 725px;height: 500px;position: absolute;left: -110px;">
                <h6><span style="color: #0c84ff">您正在做的业务是：生产管理--产品生产工序设计--产品生产工序设计单变更</span></h6>
                <div class="modal-header">
                    <table class="table" id="DFileY0012Table">

                    </table>
                </div>
            </div>
        </div>
    </form>
    <script>
        $(":input[name='changer']").val('${sysUsers.loginId}')
        $(":input[name='changeTime']").val(new Date().toLocaleString())
        var i=1;
        $(function () {
            $.post("../../MDesignProcedure/showMDesignProcedureById",{id:'${param.id}'},function (data) {
                $.each(data,function (key,value) {
                    if(key=="changer"){
                        return ;
                    }
                    if(key=="changeTime"){
                        return ;
                    }
                    $("#theTable :input[name="+key+"]").val(value)
                    $("#theObjTable :input[name="+key+"]").val(value)
                })
            })
            $.post("../../MDesignProcedure/showMDesignProcedureDetailsByParentId",{id:'${param.id}'},function (data) {
                $.each(data,function (index,item) {
                    var tr=$("<tr>" +
                        "<td><input name='detailsNumber' style='outline: none;border: 0px;width:32px' value='"+i+"'></td>" +
                        "<td><input name='procedureName' readonly style='outline: none;width:140px;border: 0px' value='" + item.procedureName + "'></td>" +
                        "<td><input name='procedureId' readonly style='outline: none;width:120px;border: 0px' value='" + item.procedureId + "'></td>" +
                        "<td><input name='procedureDescribe' readonly style='outline: none;width:120px;border: 0px' value='" + item.procedureDescribe + "'></td>" +
                        "<td><input name='labourHourAmount' value='"+item.labourHourAmount+"' type='number' required onchange='xj(this)' style='border: 0px;width: 100px;background-color: #d5f8f1' min='1'></td>" +
                        "<td><input name='amountUnit' value='"+item.amountUnit+"' style='outline: none;width:120px;border: 0px;background-color: #d5f8f1''></td>" +
                        "<td><input name='costPrice' value='"+item.costPrice+"' type='number' required onchange='xj(this)' style='border: 0px;width: 100px;background-color: #d5f8f1' min='1'></td>" +
                        "<td><input name='subtotal' value='"+item.subtotal+"' readonly style='outline: none;width:100px;border: 0px'>" +
                        "<td><div style='width: 35px'>" +
                            "<a href='javascript:void(0)' onclick='del(this)'>删除</a>" +
                        "</div></td>" +
                        "</tr>")
                    i=i+1;
                    $("#tableOnlineEdit").append(tr);
                })
            })
        })
        function xj(number) {
            number = $(number);
            if (number.val() == "") {
                alert("数量不能为空")
                number.val(1)
            }
            var arr = number.val().split(".")
            number.val(arr[0])
            var num = number.parent().parent().find(":input[name='labourHourAmount']").val()
            var price = number.parent().parent().find(":input[name='costPrice']").val();
            var sum=num * price;
            number.parent().parent().find(":input[name='subtotal']").val(sum)
            var cost=0;
            $(":input[name='subtotal']").each(function (index,item) {
                cost=cost+parseInt(item.value)
            })
            $(":input[name='costPriceSum']").val(cost)
        }
        function rk(data) {
            data = JSON.parse(data)
            $.each(data, function (key, value) {
                if (key == "procedureId") {
                    procedureId = value
                }
                if (key == "procedureName") {
                    procedureName = value
                }
                if (key == "procedureDescribe") {
                    procedureDescribe = value
                }
                if (key == "labourHourAmount") {
                    labourHourAmount = value
                }
                if (key == "amountUnit") {
                    amountUnit = value
                }
                if (key == "costPrice") {
                    costPrice = value
                }
                if (key == "subtotal") {
                    subtotal = value
                }
            })
            var tr = $("<tr>" +
                "<td><input type='checkbox' name='detailsNumber' style='width: 32px' value='" + i + "'></td>" +
                "<td><input name='procedureName' readonly style='outline: none;width:140px;border: 0px' value='" + procedureName + "'></td>" +
                "<td><input name='procedureId' readonly style='outline: none;width:120px;border: 0px' value='" + procedureId + "'></td>" +
                "<td><input name='procedureDescribe' readonly style='outline: none;width:120px;border: 0px' value='" + procedureDescribe + "'></td>" +
                "<td><input name='labourHourAmount' type='number' required onchange='xj(this)' style='border: 0px;width: 100px;background-color: #d5f8f1' min='1'></td>" +
                "<td><input name='amountUnit' style='outline: none;width:120px;border: 0px;background-color: #d5f8f1''></td>" +
                "<td><input name='costPrice' type='number' required onchange='xj(this)' style='border: 0px;width: 100px;background-color: #d5f8f1' min='1'></td>" +
                "<td><input name='subtotal' readonly style='outline: none;width:100px;border: 0px'>" +
                "</tr>")
            i = i + 1;
            var td = $("#tableOnlineEdit").find("td");
            var n = 0;
            $.each(td, function (index, item) {
                if ($(item).children().val() == procedureId) {
                    n = 1;
                }
            })
            if (n != 1) {
                $("#tableOnlineEdit").append(tr);
            }
        }
        $("#add").click(function () {
            $("#modalform").modal("show");
        })
        $("#del").click(function () {
            if($(":checkbox:checked").length==0){
                alert("请选择后再操作!")
                return
            }
            $(":checkbox:checked").each(function (index,intem) {
                $(intem).parent().parent().remove()
                i=i-1
            })
        })
        function checkOk() {
            var id="${param.id}";
            var designId=$("#theObjTable :input[name='designId']").val()
            var designer=$("#theObjTable :input[name=designer]").val();
            var productName=$("#theObjTable :input[name=productName]").val();
            var productId=$("#theObjTable :input[name=productId]").val();
            var costPriceSum=$(":input[name='costPriceSum']").val()
            var changer=$(":input[name=changer]").val();
            var changeTime=$(":input[name=changeTime]").val();
            var procedureDescribe=$(":input[name=procedureDescribe]").val();
            var arr = new Array();
            var p=0;
            $(":input[name='detailsNumber']").each(function () {
                var detailsNumber = $(this).val()
                var procedureName = $(this).parent().parent().find("[name='procedureName']").val();
                var procedureId = $(this).parent().parent().find("[name='procedureId']").val();
                var procedureDescribe = $(this).parent().parent().find("[name='procedureDescribe']").val();
                var labourHourAmount = $(this).parent().parent().find(":input[name=labourHourAmount]").val();
                var amountUnit = $(this).parent().parent().find(":input[name=amountUnit]").val();
                var costPrice = $(this).parent().parent().find(":input[name=costPrice]").val();
                var subtotal = $(this).parent().parent().find(":input[name=subtotal]").val();
                var a = {
                    detailsNumber: detailsNumber,
                    procedureName: procedureName,
                    procedureId: procedureId,
                    procedureDescribe: procedureDescribe,
                    labourHourAmount: labourHourAmount,
                    amountUnit: amountUnit,
                    costPrice: costPrice,
                    subtotal: subtotal
                }
                if (p == 1) {
                    return
                }
                if (labourHourAmount == "") {
                    alert("工时数不能为空!")
                    $(this).parent().parent().find(":input[name=labourHourAmount]").select()
                    p = 1;
                    return;
                }
                if (costPrice == "") {
                    alert("单位工时单价不能为空!")
                    $(this).parent().parent().find(":input[name=costPrice]").select()
                    p = 1;
                    return;
                }
                arr.push(a)
            });
            if (p == 1) {
                p = 0;
                return
            }
            var arr2 = {
                id:id,
                productName: productName,
                productId: productId,
                designer: designer,
                costPriceSum:costPriceSum,
                changer: changer,
                changeTime: changeTime,
                procedureDescribe: procedureDescribe,
                list: arr
            }
            $.ajax({
                url:"/MDesignProcedure/mdesignProcedureChange",
                type:"post",
                data:JSON.stringify(arr2),
                contentType:'application/json',
                dataType:"json",
                success:function (data) {
                    alert(data.msg)
                    if(data.code=='1'){
                        location.href="change_locate.jsp";
                    }
                }
            })
        }
        function del(btn) {
            $(btn).parent().parent().parent().remove()
            i=i-1
        }
    </script>
</form>
</body>
</html>
